package com.company.多线程;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class Test {
    public static void main(String[] args) {
        List<int[]> list = new ArrayList<>();
        int[] a = {52,45,61,32,15,19};
        int[] b = {25,41,39};
        int[] c = {561,32,15,19};
        int[] d = {12,25,1,2,5,9};
        int[] e = {82,12,32,5,19};
        list.add(a);
        list.add(b);
        list.add(c);
        list.add(d);
        list.add(e);
        Vector vector = new Vector();


        for(int i=0;i<list.size();i++){
            int[] arr = list.get(i);
            new Thread(()->{
                int sum = 0;
                for (int j=0;j< arr.length;j++){
                    sum+=arr[j];
                }
                vector.add(sum);
            }).start();
        }

        new Thread(()->{
            while (vector.size()<list.size()){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
            }
            int s = 0;
            for (int i=0;i< vector.size();i++){
                s+=(int)vector.get(i);
            }
            System.out.println(s);
        }).start();
    }
}
